/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.tnmk.worktime.gui.tbl;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author Administrator
 */
public class GroupRowsCellRenderer extends DecorateDefaultTableCellRenderer {

  private static final Color SAMEGROUP_FOREGROUND = new Color(210, 210, 210);

  public GroupRowsCellRenderer() {
    super();
  }

  public GroupRowsCellRenderer(DefaultTableCellRenderer previousRenderer) {
    super(previousRenderer);
  }

  @Override
  public Component getTableCellRendererComponent(JLabel comp, JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    boolean isSameGroup = false;
    if (row > 0) {
      Object aboveRowKeyValue = table.getValueAt(row - 1, column);
      isSameGroup = (aboveRowKeyValue != null && aboveRowKeyValue.equals(value));
    }
    if (isSameGroup) {
      comp.setForeground(SAMEGROUP_FOREGROUND);
    } else {
      Color fg = UIManager.getColor("Table.dropCellForeground");
      comp.setForeground(fg);
    }
    return comp;
  }
}
